<include file="Common/common" />
<?php $statusArr = array('1'=>'上传凭证','2'=>'等待卖家确认','3'=>'订单完成'); ?>

<body>
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  	<legend style="color: rgb(240,222,112);">购买报表</legend>
			</fieldset>
			<div style="overflow-x: auto;">
				<table class="layui-table" style="color: rgb(240,222,112);">
					<thead>
							<tr style="background: rgb(57,61,73)">
								<th>编号</th>
								<!-- <th>购买用户</th> -->
								<th>出售用户</th>
								<th>联系电话</th>
								<th>积分数量</th>
								<th>订单时间</th>
								<!-- <th>付款时间</th>
								<th>完成时间</th> -->
								<th>上传凭证</th>
								<th>状态</th>
								<!-- <th>备注</th> -->
								<th>操作</th>
							</tr> 
						</thead>
						<tbody>
							<foreach name="buyList" item="vo">
								<tr style="background: #7d7d7d;color:rgb(240,222,112);">
									<td>{$vo['id']}</td>
									<!-- <td>{$vo['buy_account']}</td> -->
									<td>{$vo['sell_account']}</td>
									<td>{$vo['sellphone']}</td>
									<td>{$vo['num']}</td>
									<td><?php if(!empty($vo['buytime'])){echo date('Y-m-d H:i:s',$vo['buytime']);} ?></td>
									<!-- <td><?php if(!empty($vo['paytime'])){echo date('Y-m-d H:i:s',$vo['paytime']);} ?></td>
									<td><?php if(!empty($vo['finishtime'])){echo date('Y-m-d H:i:s',$vo['finishtime']);} ?></td> -->
									<td><if condition="$vo['status'] egt 1 and $vo['status'] elt 2"><button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" onclick="func_order(this,{$vo['id']})" >向卖家付款/添加凭证</button></if></td>
									<td>
										<if condition="$vo['status'] eq 1">
											<if condition="$vo['pic_url'] neq ''">
												<span style="color:rgb(240,222,112);">凭证已上传</span>
											<else/>
												<span>{$statusArr[$vo['status']]}</span>
											</if>
										<else/>
											<span>{$statusArr[$vo['status']]}</span>
										</if>
									</td>
									<td>
										<if condition="$vo['status'] eq 1">
											<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" onclick="func_finish(this,{$vo['id']})" >确认提交</button>
										</if>
										
									</td>
								</tr>
							</foreach>
						</tbody>
				</table>
			</div>
			<div class="green-black">{$page}</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	// 查看订单
	function func_order(obj,id){
		var width = $(window).width() + "px";
  		var height = $(window).height() + "px";
  
		layer.open({
			type: 2,
			title: '编号：'+id,
			shadeClose: true,
			shade: 0.8,
			scrollbar: false,
			area: [width, height],
			content: ["/Order/orderdetail?id="+id,'no'] , //iframe的url
			// cancel: function(){ 
		 //    	//右上角关闭回调
		 //    	location.reload();
		 //  	}
		});
	}


	function func_finish(obj,id){
		layer.confirm('确定向卖家已付款，凭证已上传',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('Order/ctrl_buyfinish')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
                        layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
	            		setTimeout(function(){location.reload();}, 1000);
	            	}else{
                        layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
	            	}
	               	
	            }
	        });
		});
	}
</script>
<include file="Common/footer" />